package com.huika.dealontop.control.pay.utils;

import android.content.Intent;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.google.gson.reflect.TypeToken;
import com.huika.dealontop.GlobalApp;
import com.huika.dealontop.config.Constants;
import com.huika.dealontop.config.UrlConstants;
import com.huika.dealontop.control.base.BaseAct;
import com.huika.dealontop.control.pay.activity.PaysBuyPayActivity;
import com.huika.dealontop.support.http.FormResultRequest;
import com.huika.dealontop.support.http.JSONWrapAjaxParams;
import com.huika.dealontop.support.http.RequestResult;
import com.huika.dealontop.utils.DebugTool;

/**
 * Description:
 * Created by zhouweiyong on 2016/1/12.
 */
public class PaysBuyPay extends BasePay{

    private BaseAct baseAct;

    public PaysBuyPay(BaseAct baseAct) {
        this.baseAct = baseAct;
    }

    @Override
    public void pay() {
        JSONWrapAjaxParams ajaxParams = new JSONWrapAjaxParams();
        ajaxParams.putCommonTypeParam("userID", GlobalApp.getInstance().getUserId());
        ajaxParams.putCommonTypeParam("Amount", getTotalMoney());
        ajaxParams.putCommonTypeParam("PaymentOrderId", getPayOrderNo());
        FormResultRequest<String> request = new FormResultRequest<String>(UrlConstants.PASYSBUYSERVRES, new Response.Listener<RequestResult<String>>() {

            @Override
            public void onResponse(RequestResult<String> arg0) {
                DebugTool.i("zwy", arg0.getRs());
                Intent intent = new Intent(baseAct, PaysBuyPayActivity.class);
                intent.putExtra(Constants.PAYSBUY_URL,arg0.getRs());
                intent.putExtra(Constants.PAY_PAYMENTORDERID,getPayOrderNo());
                baseAct.showActivity(baseAct,intent);
            }
        }, new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError arg0) {
                DebugTool.i("zwy","");
            }
        },new TypeToken<RequestResult<String>>() {}.getType());
        request.setRequestParams(ajaxParams);
        baseAct.executeRequest(request);
    }



}
